package com.myiam.idm.connector.transformers;

import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;

import org.mule.transformer.AbstractMessageTransformer;
import org.mule.transformer.types.DataTypeFactory;
import org.mule.transport.email.MailProperties;

import com.myiam.idm.core.model.Identity;

public class IdentityToEmailTransformer extends AbstractMessageTransformer {
	
	
	 public IdentityToEmailTransformer()
	    {
	        super();
	        registerSourceType(DataTypeFactory.create(Identity.class));
	        setReturnDataType(DataTypeFactory.STRING);
	    }

	    @Override
	    public Object transformMessage(MuleMessage message, String outputEncoding) throws TransformerException
	    {
	    	Identity identity = (Identity) message.getPayload();


	        String body =  "welcome  + " + identity.getFirstName();

	        String email = identity.getEmails().get(1).getEmailAsString();
	        message.setOutboundProperty(MailProperties.TO_ADDRESSES_PROPERTY, email);

	        logger.info("Sending e-mail notification to " + email);
	        return body;
	    }
}
